package model

// Cart 购物车结构体
type Cart struct {
	BaseModel
	UserId int64 `json:"userId"`
	User   User  `gorm:"foreignKey:ID;reference:UserID"`
}

// NewCart 实例化
func NewCart(uid int64) *Cart {
	return &Cart{
		UserId: uid,
	}
}

// TableName 声明表名
func (Cart) TableName() string {
	return "shopping_cart"
}

// Item
type Item struct {
	BaseModel
	Product   Product `gorm:"foreignKey:ProductID"`
	ProductID int64
	Count     int
	CartId    int64
	Cart      Cart `gorm:"foreignkey:CartID" json:"-"`
}

// NewCartItem 实例化
func NewCartItem(productId int64, cartId int64, count int) *Item {
	return &Item{
		ProductID: productId,
		Count:     count,
		CartId:    cartId,
	}
}

// TableName 声明表明
func (Item) TableName() string {
	return "shoppiing_item"
}
